/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bsu.cs342.lab1.cache;

import java.io.File;

/**
 *
 * @author Sam Jenkins
 */
public class Test {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int arguments = args.length;
        if (arguments != 2){
            System.out.println("\nThere needs to be two arguments in the follwoing format:\n" +
                    "java Test <cache size >0 & <= 10000> <input textfile name>\n");
            System.exit(0);
        }
        Integer maxCacheSize = null;
        File file = null;
        try {        

        file = new File(args[1]);
        if(!file.exists() || !file.isFile() || !file.canRead()){
            System.out.println("\nThe file name entered does not exist, is not recognized as a file.\n" +
                    "or is not readable.\n\n" +
                    "Please check the spelling, file type (.txt) and directory of the file and try again.\n");
            System.exit(0);
        }
            maxCacheSize = new Integer(args[0]);
        
        if (arguments != 2 || maxCacheSize >= 10000 || maxCacheSize <= 0) 
        {
            System.out.println("\nIncorrect argument format!\n" +
                    "Please try this format\n:  " +
                    "java Test <cache size >0 & <= 10000> <input textfile name>\n");
        }                        
        } catch (NumberFormatException numberFormatException) {
            System.out.println("\nIncorrect <cache size> argument!\nThe cache value entered was not an integer");
        } catch (SecurityException e) {
            System.out.println("\nSecurity settings exist that do not allow this file to be read.\n" +
                    "Please check the file name and settings and try again.\n");
        }
        CacheFileProcessor cacheFileProcessor = new CacheFileProcessor();
        cacheFileProcessor.processFile(maxCacheSize, file);
    }
}